"use strict";
cc._RF.push(module, 'd4f364w3ptGDbn3wzP4AxDr', 'LineLogic');
// scripts/LineLogic.ts

Object.defineProperty(exports, "__esModule", { value: true });
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var LineLogic = /** @class */ (function (_super) {
    __extends(LineLogic, _super);
    function LineLogic() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.points = [];
        _this.eachLineWidth = 20;
        _this.dashed = null;
        return _this;
    }
    LineLogic.prototype.onLoad = function () {
        this.dashedDraw = this.dashed.getComponent(cc.Graphics);
        this.draw = this.getComponent(cc.Graphics);
        console.log('加载完毕');
    };
    LineLogic.prototype.start = function () {
    };
    LineLogic.prototype.onTouchStart = function (e) {
        console.log('测试');
        var pos = e.getLocation();
        this.preWorldPoint = pos;
        pos = this.node.convertToNodeSpaceAR(pos);
        this.prePoint = pos;
        this.points.push(cc.v2(pos.x, pos.y));
        this.draw.clear();
        this.draw.moveTo(pos.x, pos.y);
        return true;
    };
    LineLogic.prototype.onTouchMove = function (e) {
        var pos = e.getLocation();
        var nowWorldPoint = pos;
        pos = this.node.convertToNodeSpaceAR(pos);
        var disX = pos.x - this.prePoint.x;
        var disY = pos.y - this.prePoint.y;
        var dis = Math.sqrt(disX * disX + disY * disY);
        if (dis >= this.eachLineWidth) {
            // 射线检测
            var result = cc.director.getPhysicsManager().rayCast(this.preWorldPoint, nowWorldPoint, cc.RayCastType.All);
            if (result.length <= 0) {
                this.points.push(cc.v2(pos.x, pos.y));
                this.draw.lineTo(pos.x, pos.y);
                this.draw.stroke();
                this.prePoint = pos;
                this.preWorldPoint = nowWorldPoint;
                this.dashedDraw.clear();
            }
            else {
                console.log('aaaaaa');
                this.dashedDraw.clear();
                this.dashedDraw.moveTo(this.prePoint.x, this.prePoint.y);
                this.dashedDraw.lineTo(pos.x, pos.y);
                this.dashedDraw.stroke();
            }
        }
    };
    LineLogic.prototype.onTouchEnd = function (e) {
        this.dashedDraw.clear();
        var len = this.points.length;
        this.addComponent(cc.RigidBody);
        var collider = this.addComponent('MyPhysicsCollider');
        collider.points = this.points;
        collider.density = 120;
        collider.friction = 0.99;
        collider.apply();
    };
    __decorate([
        property(cc.Node)
    ], LineLogic.prototype, "dashed", void 0);
    LineLogic = __decorate([
        ccclass
    ], LineLogic);
    return LineLogic;
}(cc.Component));
exports.default = LineLogic;

cc._RF.pop();